using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Windy.DragonCurve
{
    public static class SymbolsExtension
    {
        public static SymbolTypes GetSymbolType(this Symbols symbol)
        {
            return (SymbolTypes)((int)symbol & 0x80);
        }

        public static bool IsContantSymbol(this Symbols symbol)
        {
            return symbol.GetSymbolType() == SymbolTypes.ContantSymbol;
        }

        public static bool IsVariableSymbol(this Symbols symbol)
        {
            return symbol.GetSymbolType() == SymbolTypes.VariableSymbol;
        }

        public static string ToSymbolString(this Symbols symbol)
        {
            switch (symbol)
            {
                case Symbols.F:
                    return "F";
                case Symbols.Plus:
                    return "+";
                case Symbols.Minus:
                    return "-";
                case Symbols.X:
                    return "X";
                case Symbols.Y:
                    return "Y";
                default:
                    throw new Exception("Unexpected Symbol");
            }
        }

        public static string ToSymbolString(this IEnumerable<Symbols> symbols)
        {
            StringBuilder result = new StringBuilder();

            foreach (var fo in symbols)
            {
                switch (fo)
                {
                    case Windy.DragonCurve.Symbols.F:
                        result.Append('F');
                        break;
                    case Windy.DragonCurve.Symbols.Plus:
                        result.Append('+');
                        break;
                    case Windy.DragonCurve.Symbols.Minus:
                        result.Append('-');
                        break;
                    case Windy.DragonCurve.Symbols.X:
                        result.Append('X');
                        break;
                    case Windy.DragonCurve.Symbols.Y:
                        result.Append('Y');
                        break;
                    default:
                        throw new Exception("Unexpected Symbol");;
                }
            }
            result.AppendLine();

            return result.ToString();
        }
    }
}
